import { get,post } from '../../http/axios'

export default {
    // 命名空间
    namespaced: true,
    // 状态
    state: {
        article: {},
        category:{},
        detail:{}
    },
    // 突变 -> 改变state中变量的唯一方式
    mutations: {
        set_article(state,val){
            state.article = val;
        },
        set_category(state,val) {
            state.category = val;

        },
        set_detail(state,val) {
            state.detail = val;

        }
    },
    // 动作 -> methods,发送请求
    actions: {
        async page_query_article({commit}, params) {
            let res = await get('/article/pageQuery', params);
            // console.log(res.data.list);
            commit('set_article', res.data)
        },
        async saveOrUpdate({commit}, params){
            let res = await post('/article/saveOrUpdate', params);
            return res;
        },
        async findAllCategory({commit}){
            let res = await get('/category/findAll');
            commit('set_category',res.data);

        },
        async dela({commit}, params){
            let res = await get('/article/deleteById', params);
            return res;
        },
        async aritle_detail({commit},params){
            let res = await get('/article/findById',params);
            commit('set_detail',res.data);
            console.log(res.data);
            return res
        },
        
    }
}